﻿//IP地址
var login_out = "http://www.ccoalnews.com/sso/";
var sso_url = "http://203.187.176.76:9080/SSOv2/";
var sso_code = "zgmtw";

//弹出窗口位置
var iWidth=976; //弹出窗口的宽度;
var iHeight=635; //弹出窗口的高度;
var iTop = (window.screen.availHeight-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-iWidth)/2; //获得窗口的水平位置;
var window_site = "height=635, width=976,top="+iTop+",left="+iLeft+", toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";

//设置cookie
function setCookie(sName, sValue){
	if (sValue == "") sValue = "";
	//cookie过期时间为关闭浏览器时就过期
	document.cookie = sName + "=" + escape(sValue) + ";path=/";
}
//获取cookie
function doGetCookie(strName){
	var theValue = null;
	var aCookie = document.cookie.split("; ");

	for (var i=0; i < aCookie.length; i++)
	{
		var aCrumb = aCookie[i].split("=");
		if (strName == aCrumb[0]) theValue = unescape(aCrumb[1]);
	}
	if (theValue == "0") theValue = "";
	return theValue;
}
//删除cookie
function delCookie(name){
    setCookie(name,"");
}

//每5毫秒自动检测一次用户是否登录（也就是检测cookie是否存在）
window.onload=function(){
	window.setInterval("isLogin()",500);
}

//判断处理cookie
function isLogin(){
	//如果cookie中同时不包含这些，说明cookie中无用户信息，没登录
	if(doGetCookie("username_fouNder")==undefined || doGetCookie("username_fouNder")=="" || doGetCookie("username_fouNder") == null){
		$("#sso-active").show();
		$("#sso-inactive").hide();
	}else{
		var cookieValue=doGetCookie("username_fouNder");  //将用户名存在cookie中
		$("#sso-active").hide();
		$("#sso-inactive").show();
		$("#uname").text(cookieValue);  //为用户名赋值
	}
}

//sso注册
function register(){
	window.open (sso_url+"user/register","newwindow", window_site);     
}

//sso登录
function ssoLogin(){
  window.open (sso_url+"user/ssoLogin?code="+sso_code+"&redirectUrl="+login_out+"setCookie.html?","newwindow", window_site);     
}

//sso退出。设置好的 cookie会自动失效，只需设置效果即可   
function ssoLogout(){
	window.open(sso_url+"user/ssoLogout?code="+sso_code+"&from="+login_out+"delCookie.html","newwindow", window_site);   
	$("#sso-active").hide();  //隐藏已登录状态链接
    $("#sso-inactive").css("display","block");  //显示登录、注册链接
	//$("#usercenter").attr("src","");  //将iframe中会员中心的链接地址清空。
    //$("#usercenter").hide();  //隐藏iframe
	//$("#allContents")show();  //显示其他页面
} 